import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:kkhousekeep/models/house_authentication_list_entity.dart';
import 'package:kkhousekeep/page/me/house_authentication_detail_page.dart';
import 'package:kkhousekeep/widget/house_notification_item.dart';

import '../../widget/custom_app_bar.dart';
import 'house_notification_controller.dart';

class HouseNotificationPage extends StatelessWidget {
  const HouseNotificationPage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HouseNotificationController>(
      init: HouseNotificationController(),
      builder: (controller) => Scaffold(
        backgroundColor: const Color(0xFFf4f5f6),
        appBar: CustomAppBar("房屋通知"),
        body: SafeArea(
          left: false,
          right: false,
          child: SizedBox(
            width: double.infinity,
            child: Obx(() => _buildList(controller)),
          ),
        ),
      ),
    );
  }

  Widget _buildList(HouseNotificationController controller) {
    return controller.houseNotificationList.isNotEmpty
        ? Padding(
            padding: EdgeInsets.only(top: 16.h),
            child: ListView.separated(
                itemBuilder: (context, index) {
                  return _buildHouseNotificationItem(
                      context, controller.houseNotificationList[index]);
                },
                separatorBuilder: (context, index) => const Divider(
                      height: 0,
                      thickness: 0,
                      indent: 0,
                      color: Colors.transparent,
                    ),
                itemCount: controller.houseNotificationList.length),
          )
        : Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Image.asset(
          "assets/images/hone_service_notification.png",
          width: 288.w,
          height: 358.w,
        ),
        Text(
          "暂无通知",
          style:
          TextStyle(color: const Color(0xFF999999), fontSize: 28.sp),
        ),
      ],
    );
  }

  Widget? _buildHouseNotificationItem(BuildContext context,
      HouseAuthenticationListObjList houseAuthenticationNotification) {
    return HouseNotificationItem(houseAuthenticationNotification, () {
      // 跳转房屋详情
      Get.to(const HouseAuthenticationDetailPage(),
          arguments: houseAuthenticationNotification);
    });
  }
}
